<script lang="ts" setup>
import { ref, onMounted, nextTick } from 'vue'
import { ElMessage, ElMessageBox, ElLoading } from 'element-plus'
import axios from '@/request/http'
import { useMainStore } from '@/store/main'
import Draggable from 'vuedraggable'
import { Calendar, Search } from '@element-plus/icons-vue'
import yspglService from '@/api/yspgl'
import wjfwSerivce from '@/api/wjfw'
import detailItem from './components/detail-item.vue'

const store = useMainStore()

const emit = defineEmits(['ysplbChangeEvent'])
const tagsList = ref()

const file = ref()
// 入参

// 生命周期
onMounted(() => {
  //
})

const activeName = ref('first')

const getWjxqxx = (data: any) => {
  if (Object.keys(data).length === 0) return (wjxqxxList.value = [])
  if (data.wjxh && data.wjxh.length !== 0) {
    wjxqxxList.value = [data]
    loadDetail(data)
  } else {
    wjxqxxList.value = []
  }
  // 缓存
  // cacheList.value = [cloneDeep(data)]
}

// 复选框绑定数据
const checkboxData = ref<any[]>([])
const wjxqxxList = ref<any>([])

const checkChange = (data: any) => {
  checkboxData.value = data
}

/*
 * 刷新
 */
const refresh = () => {
  emit('ysplbChangeEvent')
}

/* 展示详情 */
const currentItem = ref<any>({})
const loadDetail = (item: any) => {
  currentItem.value = { ...item }
}

/* 关闭详情 */
const closeDetail = () => {
  currentItem.value = {}
}

defineExpose({ getWjxqxx, closeDetail })
</script>
<template>
  <div class="container">
    <el-tabs v-model="activeName" class="demo-tabs" type="card">
      <el-tab-pane label="音像" name="first">
        <div class="content">
          <!-- 头部 -->
          <div class="top">
            <div class="topLeft">
              <img src="@/assets/images/yjqqs.png" alt="" />
              <p>{{ store.$state.nodeTreeData?.mc }}</p>
            </div>
          </div>
          <!-- 内容区域 -->
          <div class="center">
            <div class="writingsBox">
              <div class="writingsItem" v-for="element in wjxqxxList" :key="element.wjbh">
                <div class="item-content">
                  <div class="content-header">
                    <el-checkbox-group v-model="checkboxData" @change="checkChange">
                      <el-checkbox :value="element"></el-checkbox>
                    </el-checkbox-group>
                    <img src="@/assets/images/ellipse.png" alt="" />
                  </div>
                  <template
                    v-if="
                      store.$state.nodeTreeData?.mllxdm === 'gd0020001' ||
                      store.$state.nodeTreeData?.mllxdm === 'gd0020002'
                    "
                  >
                    <div class="content-img" @click.stop="loadDetail(element)">
                      <img src="@/assets/images/play.png" />
                    </div>
                  </template>
                  <template v-if="store.$state.nodeTreeData?.mllxdm === 'gd0020003'">
                    <div class="photo-imgs" @click.stop="loadDetail(element)">
                      <img
                        :src="`${axios.defaults.baseURL}/fpi/wjfw/download?wjbh=${element.wjbh}`"
                      />
                    </div>
                  </template>
                  <div class="content-footer" v-if="element.jcztmc">{{ element.ysplbmc }}</div>
                </div>
                <div class="pageNumber">1</div>
                <!-- <div class="title">{{ element.label }}</div> -->
              </div>
            </div>
          </div>
          <!-- 展示详情 -->
          <detail-item
            :current-item="currentItem"
            class="detail-wrapper"
            @close="closeDetail"
            v-if="currentItem.wjxh"
          ></detail-item>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;
  .content {
    width: 100%;
    height: 100%;
    padding: 5px;
    display: flex;
    flex-direction: column;
    .top {
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid #dae4f1;
      padding-bottom: 5px;
      margin-bottom: 5px;
      .topLeft {
        display: flex;

        img {
          padding-right: 5px;
        }
        p {
          font-weight: 600;
        }
      }
    }
    .buttomGroup {
      width: 100%;
      display: flex;
      justify-content: space-between;
      margin-bottom: 5px;
      .rowbutton {
        display: flex;
      }
    }

    .center {
      padding: 15px;
      background-color: #f7f8f9;
      // flex: 1;
      // flex-shrink: 0;
      height: 650px;
      overflow: auto;
      display: flex;
      flex-direction: column;
      .headerButtomGroup {
        .header-text {
          color: #4a76ab;
        }
        .header-text + .header-text {
          margin-left: 10px;
        }
        .header-avtive {
          color: #fff;
          background-color: #3c89d0;
        }
      }

      .writingsBox {
        overflow-y: auto;
        max-height: 100%;
        display: flex;
        flex-wrap: wrap;
        margin-top: 10px;
        .writingsItem {
          width: 212px;
          padding: 0 16px 10px 0;
          display: flex;
          flex-direction: column;

          .item-content {
            display: flex;
            flex-direction: column;
            flex: 1;
            flex-shrink: 0;
            background-color: #fff;
            box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
            cursor: pointer;
            .content-header {
              display: flex;
              justify-content: space-between;
              align-items: center;
              padding: 0 10px;
              img {
                width: 15px;
                height: 15px;
              }
            }

            .content-img {
              margin: 0 10px 10px 10px;
              flex: 1;
              flex-shrink: 0;
              background-color: #b3c6d1;
              display: flex;
              justify-content: center;
              align-items: center;

              // & > img {
              //   width: 100%;
              //   height: 194px;
              // }
            }

            .photo-imgs {
              margin: 0 10px 10px 10px;
              flex: 1;
              flex-shrink: 0;
              img {
                width: 100%;
                height: 100%;
              }
            }

            .content-footer {
              width: 100%;
              text-align: center;
              padding: 5px 0;
              background-color: #f7c863;
            }
          }

          .pageNumber {
            height: 26px;
            line-height: 26px;
            text-align: center;
          }
        }
      }
    }

    .bottomButton {
      margin-top: 10px;
    }
  }
}

.export-excel {
  li {
    text-align: center;
    height: 30px;
    line-height: 30px;
    cursor: pointer;
    &:hover {
      background-color: #ecf5ff;
      color: #266df5;
    }
  }
}
.detail-wrapper {
  width: 100%;
  height: 100%;
  background-color: #fff;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 999;
}
</style>
